<?php
/*************************************************************************
Category module
----------------------------------------------------------------
Avasoft CMS Project
Company: Avasoft Co., Ltd                                  
Name: Tran Thi Kim Que
Last updated: 08/03/2011
**************************************************************************/
include_once(ROOT_PATH."classes/dao/categories.class.php");
include_once(ROOT_PATH."classes/dao/entries.class.php");
include_once(ROOT_PATH."includes/functions.php");
$categories = new Categories();
$entries = new Entries();
$templateFile = "category.tpl.html";
$slug = $request->element('slug','');
$page = $request->element('page',1);
$catslugItem = $categories->getCategoryFromSlug($slug);
$item_news_per_row = $siteConfigs->getProperty('item_news_per_row');
if($catslugItem){
	$cid = $catslugItem->getId();
	$activeItems= $categories->getParentAllFromCid($cid);
	$active=$activeItems[0];
	$template->assign('active',$active);
	$subcat =$categories->getSubCategory1($cid); 
	$entriesItems = $entries->getObjects($page,"status=1 AND cid in($subcat) AND lang='$lang'",array('position'=>'ASC'),$item_news_per_row);
	$pages = $entries->getNumItems('id', "cid in ($subcat) AND `status` = 1 AND lang='$lang'",$item_news_per_row);
	//print_r($entriesItems);
	$rows = $pages['rows'];
	$pages = $pages['pages'];
	if(!$pages) $pages=1;
	if($page>$pages) $page=$pages;	
	$listPage = linkPager1_en($catslugItem->getUrlTemplate($lang,1),$pages,$page);
	$template->assign("pager",$listPage);
	$template->assign("pages",$pages);
	$countItem=count($entriesItems);
/*	if($countItem<=1&&$cid==5)
	$templateFile = "news.tpl.html";*/
	$pageName =$catslugItem->getName($lang);
	$template->assign('pageName',$pageName);
	$template->assign('entriesItems',$entriesItems);
}
$template->assign('catslugItem',$catslugItem);
#end product
include_once(ROOT_PATH."modules/framework.module.php");

 #end tin tuc left
 $template->assign('active',$active);

?>